import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;


public class FileIOMerge {
	private HashMap<String,ArrayList<HashMap<String,String>>> a;


	public FileIOMerge(String s){
		
				Scanner inputScanner = null;
		
				a = new HashMap<String,ArrayList<HashMap<String,String>>>();
		
				try {
					inputScanner = new Scanner(new FileInputStream(s));
		
				}
				catch(FileNotFoundException e){System.out.println(e);System.exit(1);}
		
				for (int i = 1;i < 27;i++){
					switch(i){
					case(1) : a.put("a", new ArrayList<HashMap<String,String>>(10));
					case(2) : a.put("b", new ArrayList<HashMap<String,String>>(10));
					case(3) : a.put("c", new ArrayList<HashMap<String,String>>(10));
					case(4) : a.put("d", new ArrayList<HashMap<String,String>>(10));
					case(5) : a.put("e", new ArrayList<HashMap<String,String>>(10));
					case(6) : a.put("f", new ArrayList<HashMap<String,String>>(10));
					case(7) : a.put("g", new ArrayList<HashMap<String,String>>(10));
					case(8) : a.put("h", new ArrayList<HashMap<String,String>>(10));
					case(9) : a.put("i", new ArrayList<HashMap<String,String>>(10));
					case(10) : a.put("j", new ArrayList<HashMap<String,String>>(10));
					case(11) : a.put("k", new ArrayList<HashMap<String,String>>(10));
					case(12) : a.put("l", new ArrayList<HashMap<String,String>>(10));
					case(13) : a.put("m", new ArrayList<HashMap<String,String>>(10));
					case(14) : a.put("n", new ArrayList<HashMap<String,String>>(10));
					case(15) : a.put("o", new ArrayList<HashMap<String,String>>(10));
					case(16) : a.put("p", new ArrayList<HashMap<String,String>>(10));
					case(17) : a.put("q", new ArrayList<HashMap<String,String>>(10));
					case(18) : a.put("r", new ArrayList<HashMap<String,String>>(10));
					case(19) : a.put("s", new ArrayList<HashMap<String,String>>(10));
					case(20) : a.put("t", new ArrayList<HashMap<String,String>>(10));
					case(21) : a.put("u", new ArrayList<HashMap<String,String>>(10));
					case(22) : a.put("v", new ArrayList<HashMap<String,String>>(10));
					case(23) : a.put("w", new ArrayList<HashMap<String,String>>(10));
					case(24) : a.put("x", new ArrayList<HashMap<String,String>>(10));
					case(25) : a.put("y", new ArrayList<HashMap<String,String>>(10));
					case(26) : a.put("z", new ArrayList<HashMap<String,String>>(10));
					case(27) : a.put("-", new ArrayList<HashMap<String,String>>(10));
					}
				}
		
		
		fillDictionary(inputScanner);

	}

	private void fillDictionary(Scanner inputScanner){
		while (inputScanner.hasNext() == true){
			String s = inputScanner.next();
			
			String sortedString = sortWord(s);
			String tempString = sortedString.substring(0,1);
			
			if (tempString.equalsIgnoreCase(" ")) tempString = "-";
		
			ArrayList<HashMap<String,String>> temp = a.get(tempString);
			HashMap<String,String> tempMap = new HashMap<String,String>(1);
			tempMap.put(sortedString,s);
			temp.add(tempMap);
			a.put(tempString,temp);

		}
	}
	protected String sortWord(String s){
		MergeSort b = new MergeSort(s);
		String returnString = "";
		
		
		ArrayList<String> listWord = b.mergeSort(b.getTempArray());
		for (String p :listWord) returnString += p;
		
	
		return returnString;

	}

	public HashMap<String, ArrayList<HashMap<String, String>>> getA() {
		return a;
	}
	

	




}
